/**
 * Copyright 2013 ABSir's Studio
 * 
 * All right reserved
 *
 * Create on 2013-8-13 上午12:00:04
 */
package com.absir.android.goods;

import com.absir.bean.basis.Configure;
import com.absir.bean.inject.value.Inject;
import com.absir.bean.inject.value.InjectType;

/**
 * @author absir
 * 
 */
@Configure
public abstract class GoodsContextUtils {

	/** CoinGoodsDefine */
	@Inject(type = InjectType.Selectable)
	private static CoinGoodsDefine CoinGoodsDefine;

	/** GoodsDefines */
	@Inject(type = InjectType.Selectable)
	private static IGoodsDefine[] GoodsDefines;

	public static CoinGoodsDefine getCoinGoodsDefine() {
		return CoinGoodsDefine;
	}

	/**
	 * @return
	 */
	public static IGoodsDefine[] getGoodsDefines() {
		return GoodsDefines;
	}

	/**
	 * @return
	 */
	public static int getGoodsDefineCount() {
		return GoodsDefines.length;
	}

	/**
	 * @param index
	 * @return
	 */
	public static IGoodsDefine getGoodsDefineAt(int index) {
		return GoodsDefines[index];
	}

	/**
	 * @param tag
	 * @return
	 */
	public static IGoodsInfo getGoodsInfo(Object tag) {
		for (IGoodsDefine goodsDefine : GoodsDefines) {
			IGoodsInfo goodsInfo = goodsDefine.getGoodsInfo(tag);
			if (goodsInfo != null) {
				return goodsInfo;
			}
		}

		return null;
	}

	/**
	 * @param tag
	 * @return
	 */
	public static IGoodsDefine getGoodsDefine(Object tag) {
		for (IGoodsDefine goodsDefine : GoodsDefines) {
			if (goodsDefine.getGoodsInfo(tag) != null) {
				return goodsDefine;
			}
		}

		return null;
	}

	/**
	 * @param tag
	 * @return
	 */
	public static GoodsApply getGoodsApply(Object tag) {
		for (IGoodsDefine goodsDefine : GoodsDefines) {
			IGoodsInfo goodsInfo = goodsDefine.getGoodsInfo(tag);
			if (goodsInfo != null) {
				return new GoodsApply(goodsInfo, goodsDefine);
			}
		}

		return null;
	}

	/**
	 * @param tag
	 * @return
	 */
	public static int getGoodsInfoCount(Object tag) {
		IGoodsDefine goodsDefine = getGoodsDefine(tag);
		return goodsDefine == null ? -1 : goodsDefine.getGoodsInfoCount(tag);
	}
}
